home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 October / Macformat17.cdr / Shareware City / Developers / WASTETCL / WASTE TCL / CWASTEDlgText.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-02  |  5.0 KB  |  210 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CWASTEDlgText.c
  3.  
  4.     A class with some of the functionality of CDialogText, but using CWASTEText
  5.  
  6.  ******************************************************************************/
  7.  
  8. #ifdef TCL_PCH
  9. #include <TCLHeaders>
  10. #endif
  11.  
  12. #include "CWASTEDlgText.h"
  13. #include "CDialog.h"
  14. #include <CPaneBorder.h>
  15.  
  16. #define kBorderAmount    2    // white space between border and text of edit field
  17.  
  18. extern CBartender    *gBartender;
  19. extern CBureaucrat        *gGopher;        // First in line to get commands
  20.  
  21. static pascal void WEPostUpdate(WEHandle hWE, long fixLength, long inputAreaStart,
  22.     long inputAreaEnd, long pinRangeStart, long pinRangeEnd);
  23.  
  24. extern CWASTEText    *gWASTEText;                /* Current WASTEText object */
  25.  
  26. TCL_DEFINE_CLASS_D1(CWASTEDlgText, CWASTEText);
  27.  
  28.  
  29. /********************************************************\
  30.  CWASTEDlgText - default constructor
  31. \********************************************************/
  32.  
  33. CWASTEDlgText::CWASTEDlgText()
  34. {
  35.     TCL_END_CONSTRUCTOR
  36. }
  37.  
  38.  
  39. /********************************************************\
  40.  CWASTEDlgText - constructor
  41. \********************************************************/
  42.  
  43. CWASTEDlgText::CWASTEDlgText(
  44.     CView            *anEnclosure,
  45.     CView            *aSupervisor,
  46.     short            aWidth,
  47.     short            aHeight,
  48.     short            aHEncl,
  49.     short            aVEncl,
  50.     SizingOption    aHSizing,
  51.     SizingOption    aVSizing,
  52.     short            aLineWidth,
  53.     Boolean            aScrollHoriz,
  54.     Boolean            aIsRequired,
  55.     long            aMaxValidLength,
  56.     Boolean            aValidateOnResign)
  57.  
  58.     : CWASTEText(anEnclosure, aSupervisor,
  59.         aWidth, aHeight, aHEncl, aVEncl,
  60.         aHSizing, aVSizing, aLineWidth, aScrollHoriz)
  61. {
  62.  
  63.     IWASTEDlgTextX();
  64.     TCL_END_CONSTRUCTOR
  65. }
  66.  
  67.  
  68. /********************************************************\
  69.  ~CWASTEDlgText - destructor
  70. \********************************************************/
  71.  
  72. CWASTEDlgText::~CWASTEDlgText()
  73. {
  74.     TCL_START_DESTRUCTOR
  75. }
  76.  
  77.  
  78. /********************************************************\
  79.  IWASTEDlgText - initializer, if used with default
  80.      constructor
  81. \********************************************************/
  82.  
  83. void CWASTEDlgText::IWASTEDlgText(CView *anEnclosure, CView *aSupervisor,
  84.                 short aWidth, short aHeight,
  85.                 short aHEncl, short aVEncl,
  86.                 SizingOption aHSizing, SizingOption aVSizing,
  87.                 short aLineWidth)
  88. {
  89.  
  90.     CWASTEText::IWASTEText(anEnclosure, aSupervisor,
  91.         aWidth, aHeight, aHEncl, aVEncl,
  92.         aHSizing, aVSizing, aLineWidth);
  93.  
  94.     IWASTEDlgTextX();
  95. }
  96.  
  97.  
  98. /********************************************************\
  99.  IViewTemp - construct from View resource
  100. \********************************************************/
  101.  
  102. void CWASTEDlgText::IViewTemp(CView *anEnclosure, CBureaucrat *aSupervisor,
  103.                             Ptr viewData)
  104. {
  105.     CWASTEText::IViewTemp(anEnclosure, aSupervisor, viewData);
  106.  
  107.     IWASTEDlgTextX();
  108. }
  109.  
  110.  
  111. /********************************************************\
  112.  IWASTEDlgTextX - common initialization
  113. \********************************************************/
  114.  
  115. void CWASTEDlgText::IWASTEDlgTextX()
  116. {
  117.     WETSMPostUpdateProcPtr preProc;
  118.     
  119.     MakeBorder();
  120.     SetWholeLines(FALSE);
  121.     
  122.     // set preupdate routine to WEPreUpdate
  123.     preProc = &WEPostUpdate;
  124.     WESetInfo(weTSMPostUpdate, (void *)&preProc, macWE);
  125. }
  126.  
  127. /********************************************************\
  128.  WEPostUpdate -- broadcast a dialog text changed message
  129. \********************************************************/
  130.  
  131. static pascal void WEPostUpdate(WEHandle hWE, long fixLength, long inputAreaStart,
  132.     long inputAreaEnd, long pinRangeStart, long pinRangeEnd)
  133. {
  134.     short ID;
  135.     GrafPtr curPort;
  136.     
  137.     if (gWASTEText != NULL)
  138.     {
  139.         GetPort(&curPort);
  140.         ID = gWASTEText->ID;
  141.         gWASTEText->BroadcastChange(dialogTextChanged, &ID);
  142.         SetPort(curPort);
  143.     }
  144. }
  145.  
  146.  
  147. /********************************************************\
  148.  MakeBorder - put a border around the text
  149. \********************************************************/
  150.  
  151. void CWASTEDlgText::MakeBorder()
  152. {
  153.     Rect    margin;
  154.     CPaneBorder *border;
  155.  
  156.     border = TCL_NEW(CPaneBorder,());
  157.     border->IPaneBorder(kBorderFrame);
  158.     SetRect(&margin, -kBorderAmount, -kBorderAmount, kBorderAmount, kBorderAmount);
  159.     border->SetMargin(&margin);
  160.     SetBorder(border);
  161. }
  162.  
  163. /********************************************************\
  164.  DoKey - handle Tab and Return
  165. \********************************************************/
  166.  
  167. void CWASTEDlgText::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
  168. {
  169.     Boolean pass = TRUE;
  170.     short    ID;
  171.  
  172.     switch (theChar)
  173.     {
  174.         case '\t':
  175.         case '\r':
  176.         case kEnterKey:
  177.             pass = FALSE;
  178.             break;
  179.  
  180.         case kEscapeOrClear:
  181.             if (keyCode == KeyEscape) pass = FALSE;
  182.             break;
  183.     }
  184.     if (pass)
  185.     {
  186.         CWASTEText::DoKeyDown(theChar, keyCode, macEvent);
  187.  
  188.         if (itsTypingTask && itsTypingTask->CanStillType())
  189.         {
  190.             ID = this->ID;
  191.             BroadcastChange(dialogTextChanged, &ID);
  192.         }
  193.     }
  194.     else
  195.         itsSupervisor->DoKeyDown(theChar, keyCode, macEvent);
  196. }
  197.  
  198. /********************************************************\
  199.  GetTextString - return the text as a pascal string
  200. \********************************************************/
  201.  
  202. void CWASTEDlgText::GetTextString(StringPtr aString)
  203. {
  204.     short length = Min(GetLength(), 255);
  205.  
  206.     BlockMove(*GetTextHandle(), &aString[1], length);
  207.     aString[0] = length;
  208. }
  209.  
  210.